package com.boang.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boang.entity.PO.AuditLog;
import com.boang.entity.PO.OwnerApply;
import com.boang.entity.Room;
import com.boang.mapper.OwnerApplyMapper;
import com.boang.mapper.RoomMapper;
import com.boang.service.OwnerApplyService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author 22567
 * @description 针对表【owner_apply(业主申请表)】的数据库操作Service实现
 * @createDate 2025-03-06 17:17:51
 */
@Service
public class OwnerApplyServiceImpl extends ServiceImpl<OwnerApplyMapper, OwnerApply> implements OwnerApplyService {

    @Autowired
    private OwnerApplyMapper applyMapper;

    @Autowired
    private RoomMapper houseMapper;

    // 提交认证申请
    @Transactional
    public String submitApply(OwnerApply dto) {
        // 校验房屋是否已被认证
        Room room = houseMapper.selectById(dto.getHouseId());
        if (room.getOwnerId() != null) {
            return "该房屋已存在认证业主";
        }

        OwnerApply apply = new OwnerApply();
        BeanUtils.copyProperties(dto, apply);
        apply.setApplyTime(new Date());
        applyMapper.insert(apply);
        return "提交成功";
    }



}




